package vashion.azeroth.api.controller.member;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import vashion.azeroth.api.controller.base.BaseController;
import vashion.azeroth.core.personal.pojo.PersonalApproval;
import vashion.azeroth.core.personal.pojo.PersonalExperience;
import vashion.azeroth.core.result.ApiResult;
import vashion.azeroth.core.service.PersonalApprovalService;
import vashion.azeroth.core.service.PersonalExperienceService;

@Controller
@RequestMapping("/member")
public class ApprovalController<T> extends BaseController {

	@Autowired
	private PersonalApprovalService<T> personalApprovalService;

	/**
	 * 添加点赞
	 * 
	 * */
	@RequestMapping("addApproval.htm")
	@ResponseBody
	public ApiResult<Boolean> addApproval(
			@ModelAttribute("personalApproval") PersonalApproval personalApproval) {
		ApiResult<Boolean> ApiResult = personalApprovalService
				.addApproval(personalApproval);
		
		return ApiResult;
	}

	/**
	 * 取消点赞
	 * 
	 * */

	@RequestMapping("cancelApproval.htm")
	@ResponseBody
	public ApiResult<Boolean> cancelApproval(
			@ModelAttribute("personalApproval") PersonalApproval personalApproval) {

		ApiResult<Boolean> ApiResult = personalApprovalService
				.cancelApproval(personalApproval);

		return ApiResult;
	}

	/**
	 * 查询我点赞的贴子
	 * 
	 * */

	@RequestMapping("queryMyApprovalPost.htm")
	@ResponseBody
	public ApiResult<List<PersonalApproval>> queryMyApprovalPost(
			@ModelAttribute("personalApproval") PersonalApproval personalApproval) {

		Long memberId = personalApproval.getMemberId();

		if (null == memberId) {
			return null;
		}

		int pageNum = personalApproval.getPageNum();

		int pageSize = personalApproval.getPageSize();

		pageNum = (pageNum - 1) < 0 ? 1 : pageNum;

		pageNum = (pageNum - 1) * pageSize;

		ApiResult<List<PersonalApproval>> ApiResult = personalApprovalService
				.queryMyApprovalPost(memberId, pageNum, pageSize);
		return ApiResult;
	}

	/**
	 * 查询我点赞的商品
	 * 
	 * */

	@RequestMapping("queryMyApprovalItem.htm")
	@ResponseBody
	public ApiResult<List<PersonalApproval>> queryMyApprovalItem(
			@ModelAttribute("personalApproval") PersonalApproval personalApproval) {

		Long memberId = personalApproval.getMemberId();

		if (null == memberId) {
			return null;
		}

		int pageNum = personalApproval.getPageNum();

		int pageSize = personalApproval.getPageSize();

		pageNum = (pageNum - 1) < 0 ? 1 : pageNum;

		pageNum = (pageNum - 1) * pageSize;

		ApiResult<List<PersonalApproval>> ApiResult = personalApprovalService
				.queryMyApprovalItem(memberId, pageNum, pageSize);
		return ApiResult;
	}

	/**
	 * 查询文章或贴子是否已点赞
	 * 
	 * */

	@RequestMapping("queryIsApproval.htm")
	@ResponseBody
	public ApiResult<Boolean> queryIsApproval(
			@ModelAttribute("personalApproval") PersonalApproval personalApproval) {

		Long memberId = personalApproval.getMemberId();

		if (null == memberId) {
			return null;
		}

		Integer type = personalApproval.getType();

		String targetCode = personalApproval.getTargetCode();

		int pageSize = personalApproval.getPageSize();

		ApiResult<Boolean> ApiResult = personalApprovalService.queryIsApproval(
				memberId, type, targetCode);
		return ApiResult;
	}

	/**
	 * 查询文章或贴子点赞数量
	 * 
	 * */

	@RequestMapping("queryApprovalCnt.htm")
	@ResponseBody
	public ApiResult<Integer> queryApprovalCnt(
			@ModelAttribute("personalApproval") PersonalApproval personalApproval) {

		Integer type = personalApproval.getType();

		String targetCode = personalApproval.getTargetCode();

		ApiResult<Integer> result = personalApprovalService.queryApprovalCnt(
				type, targetCode);

		return result;
	}

	
	@RequestMapping("getFeedsApprovalInfo.htm")
	@ResponseBody
	public ApiResult<List<PersonalApproval>> getFeedsApprovalInfo(
			@ModelAttribute("personalApproval") PersonalApproval personalApproval) {

		Integer type = personalApproval.getType();

		String targetCode = personalApproval.getTargetCode();

		ApiResult<List<PersonalApproval>> result = personalApprovalService.getFeedsApprovalInfo(
				type, targetCode);

		return result;
	}
	
	
	
}
